package com.example.leetdemo.plan1;

import com.example.leetdemo.utils.DateUtils;
import org.bouncycastle.asn1.dvcs.Data;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Date;
import java.util.Deque;

public class Sword038 {

    private Long nihao;

    public int[] dailyTemperatures(int[] temperatures) {
        int[] t = new int[temperatures.length];
        Deque<Integer> stack = new ArrayDeque<>();
        for (int i = 0; i < temperatures.length; i++) {
            if (stack.size() == 0) {
                stack.push(i);
            } else {
               while (stack.size() > 0 && temperatures[i] > temperatures[stack.peekLast()]) {
                   t[stack.peekLast()] = i - stack.peekLast();
                   stack.pollLast();
               }
               stack.addLast(i);
            }
        }
        return t;
    }

    public static void main(String[] args) {
        Sword038 sword038 = new Sword038();
        System.err.println(Arrays.toString(sword038
                .dailyTemperatures(new int[]{73, 74, 75, 71, 69, 72, 76, 73})));

//        System.err.println(DateUtils.localDateTimeToMilli(LocalDateTime.now()) / 1000 - 2);
        long currentTime = System.currentTimeMillis();
        long startTime = 0l;
        if (startTime < currentTime) {
            startTime = currentTime;
        }
        try {
            Method method = Sword038.class.getMethod("dailyTemperatures", int[].class);
            Field[] fileds = Sword038.class.getDeclaredFields();
            for (Field field : fileds) {
                System.err.println(field.getName());
            }
            System.err.println(method.invoke(sword038, (Object) new int[]{73, 74, 75, 71, 69, 72, 76, 73}));;
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.err.println(startTime);
        System.err.println(LocalDateTime.now());
        System.err.println(new Date(startTime));
    }
}
